package com.mc.designpattern.template;

import com.mc.designpattern.strategy.channelStrategy.ChannelStrategy;
import org.assertj.core.util.Lists;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Component
public class TemplateProcessor implements ApplicationContextAware {
    private static Map<Integer, AbstractLog> strategyMap = new HashMap<>();

    /**
     * 获取所有的策略Beanclass 加入HandlerOrderContext属性中
     *
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        strategyMap.put(1, (AbstractLog) applicationContext.getBean("file1Log"));
        strategyMap.put(2, (AbstractLog) applicationContext.getBean("file2Log"));
    }


    public List<AbstractLog> getAll() {
        ArrayList<AbstractLog> objects = Lists.newArrayList();
        for (AbstractLog value : strategyMap.values()) {
            objects.add(value);
        }
        return objects;
    }
}
